﻿using FarmSmartSleep.Common.Domain.EarTage;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;

namespace FarmSmartSleep.Organ.API.Application.EarsCommands
{
    public class LambBreedSearchHander : IRequestHandler<LambBreedSearchCommand, ResultT<LambBreed>>
    {

        private readonly ILogger<LambBreedSearchHander> logger;
        private readonly IBaseRepository<LambBreed> breedRepository;

        public LambBreedSearchHander(ILogger<LambBreedSearchHander> logger, IBaseRepository<LambBreed> breedRepository)
        {
            this.logger = logger;
            this.breedRepository = breedRepository;
        }
        /// <summary>
        /// 获取产羔对应品种信息
        /// </summary>
        /// <param name="request">获取产羔对应品种信息请求对象</param>
        /// <param name="cancellationToken"></param>
        /// <returns>获取产羔对应品种信息响应对象</returns>
        public async Task<ResultT<LambBreed>> Handle(LambBreedSearchCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var result = new ResultT<LambBreed>();
                result.Data =  breedRepository.GetAll().ToList();
                return result;

            }
            catch (Exception ex )
            {
                logger.LogError("获取产羔对应品种信息方法调用出错" + ex);
                throw;
            }
        }
    }
}
